package com.shunwang.errors.client.listener;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

import com.shunwang.errors.errorinfo.ErrorInfo;
import com.shunwang.errors.errorinfo.ErrorLogger;

public class ErrorLoggerRequestListener implements ServletRequestListener{

	private final static ErrorLogger errors = ErrorLogger.getInstance();
	
	public void requestDestroyed(ServletRequestEvent event) {
		if(event.getServletRequest().getAttribute(ErrorInfo.Ident) != null){
			event.getServletRequest().removeAttribute(ErrorInfo.Ident);
			errors.removeInfo();
		}
	}

	public void requestInitialized(ServletRequestEvent event) {
		if(event.getServletRequest().getAttribute(ErrorInfo.Ident) == null){
			event.getServletRequest().setAttribute(ErrorInfo.Ident, errors.getInfo());
		}
	}

}
